package com.api.shopapi.mapper;


import com.api.shopapi.entity.Government;
import com.api.shopapi.entity.dto.GovernmentDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface GovernmentMapper {

    @Insert("insert into government" +
            "(" +
            "GovernmentCode," +
            "Name," +
            "Tel," +
            "Contacts," +
            "Address," +
            "Status," +
            "ElderlyLastAuditZoneLevel," +
            "CreateTime," +
            "TopRoleCode," +
            "Province," +
            "City," +
            "District," +
            "Town," +
            "Landmark" +
            ")values(" +
            "#{government.GovernmentCode}," +
            "#{government.Name}," +
            "#{government.Tel}," +
            "#{government.Contacts}," +
            "#{government.Address}," +
            "#{government.Status}," +
            "#{government.ElderlyLastAuditZoneLevel}," +
            "#{government.CreateTime}," +
            "#{government.TopRoleCode}," +
            "#{government.Province}," +
            "#{government.City}," +
            "#{government.District}," +
            "#{government.Town}," +
            "#{government.Landmark}" +
            ")")
    public int insert(@Param("government") Government government);


    @Delete("delete from government where governmentCode=#{governmentCode}")
    public int deleteByGovernmentCode(@Param("governmentCode") String governmentCode);


    @Update("update government set " +
            "Name=#{government.Name}," +
            "Tel=#{government.Tel}," +
            "Contacts=#{government.Contacts}," +
            "Address=#{government.Address}," +
            "ElderlyLastAuditZoneLevel=#{government.ElderlyLastAuditZoneLevel}," +
            "Status=#{government.Status}, " +
            "TopRoleCode=#{government.TopRoleCode} ," +
            "Province=#{government.Province} ," +
            "City=#{government.City} ," +
            "District=#{government.District} ," +
            "Town=#{government.Town} ," +
            "Landmark=#{government.Landmark} " +
            " where GovernmentCode=#{government.GovernmentCode}")
    public int updateByGovernmentCode(@Param("government") Government government);


    @Select("select * from government where governmentCode=#{governmentCode} limit 1")
    public Government getByGovernmentCode(@Param("governmentCode") String governmentCode);


    @Select("select * from government order by CreateTime asc")
    public List<Government> getList();

    @Select("<script>"
            +"select * from government where 1 = 1 "
            +"<if test='status != -1'>"
            +" and status = #{status}"
            +"</if>"
            +"</script>")
    public List<Government> getList2(@Param("status") int status);

    @Select("select * from government order by CreateTime desc")
    public List<GovernmentDTO> getListDTO();

    @Select("select  GovernmentCode from  government")
    List<Government> getAllGovernmentCode();

    @Select("select  * from  government where City=#{city} and Status =1 ")
    List<Government> getByCity(@Param("city") String city);

    @Select("select * from government where Status = 1 ")
    List<Government> getNormalGovernment();





}
